import EarlyWarning from "./earlyWarning"
import * as Cesium from "cesium"
import HashMap from "../uitls/hashMap"
import {get,post} from "@/ajax/http";
import "leaflet"
import '../uitls/leaflet-ext/proj4-compressed'
import '../uitls/leaflet-ext/proj4leaflet.js'
import {
    message,
} from 'antd';
const crs = new L.Proj.CRS("EPSG:32648","+proj=utm +zone=48 +datum=WGS84 +units=m +no_defs",{})
const pushWarning = function(viewer){
    this.viewer = viewer
    this.earlyWarning = new EarlyWarning(viewer)
    //一维预警对象列表
    this.warningObjs = []
    this.warningTowKeys = []
    this.warningType = [
        "",
        "蓝色预警",
        "黄色预警",
        "橙色预警",
        "红色预警"
    ]
    this.warningstyle = [
        "",
        new Cesium.Color(0, 0, 1, 1),
        new Cesium.Color(1, 1, 0, 1),
        new Cesium.Color(0.8, 0.8, 0.1, 1),
        new Cesium.Color(1, 0, 0, 1),
    ]
    var self = this
    this.dashPattern = 5
    this.setTimeout = setInterval(function(){
        if(self.dashPattern<15){
            self.dashPattern+=5
        }else{
            self.dashPattern = 5
        }
        
    },200)
}
pushWarning.prototype = {
    addWarning(){
            //将预警对象添加到预警显示队列
        this.warningObjs.push({
            position:{
                lat:warningobjTems.position.lat,
                lon:warningobjTems.position.lon
            },
            level:warningLv,
            content:`<ul>
                <li>断面名称:${warningobjTems.info.name}</li>
                <li>预警阈值:${IndexThresholdArr.join("|")}</li>
                <li>当前水位:${resultobj.level}</li>
                <li>预警级别:${this.warningType[warningLv]}</li>
            </ul>`
        })
    },
    addtwoWarning(warningObj){
        var self = this
        var bData = new Cesium.Entity({
            id:warningObj.id,
            position: Cesium.Cartesian3.fromDegrees(warningObj.points[0][0],warningObj.points[0][1],0),
            label: {
                text: this.warningType[warningObj.level]+"|"+warningObj.info,
                font : '14px sans-serif',
                fillColor : this.warningstyle[warningObj.level],
                style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                outlineWidth : 2,
                verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
                pixelOffset : new Cesium.Cartesian2(20, -40),
                heightReference:Cesium.HeightReference.CLAMP_TO_GROUND
            },
            polyline :{
                positions: Cesium.Cartesian3.fromDegreesArray(warningObj.points[0]),
                clampToGround: true,
                width: 3,
                material : new Cesium.PolylineDashMaterialProperty({
                    color : this.warningstyle[warningObj.level],
                    dashLength:new Cesium.CallbackProperty(function () {
                        return self.dashPattern
                        
                    }, false)
                }),
                show: true
            }
        })
        this.warningTowKeys.push(warningObj.id)
        this.viewer.entities.add(bData); //添加到场景
        this.viewer.flyTo(bData,{
            maximumHeight:100,
            offset : {
                heading : Cesium.Math.toRadians(0.0),
                pitch : Cesium.Math.toRadians(-45),
                range : 0
            }
            // offset:
        })
    },
    gotoWarning(id){
        var curEntity = this.viewer.entities.getById(id)
        this.viewer.flyTo(curEntity,{
            maximumHeight:100,
            offset : {
                heading : Cesium.Math.toRadians(0.0),
                pitch : Cesium.Math.toRadians(-45),
                range : 0
            }
            // offset:
        })
    },
    clearWarning(){
        this.warningObjs = []
        this.warningtwoObjs = []
        this.earlyWarning.clearAll()
        this.warningTowKeys.forEach((warningKey,index) => {
            this.viewer.entities.removeById(warningKey);
            if(index == this.warningTowKeys.length-1){
                this.warningTowKeys = []
            }
        });
    },
    //展示预警信息
    showWarning() {
        this.earlyWarning.clearAll()
        //在地图上展示预警信息
        this.earlyWarning.stationWarningToMap(this.warningObjs)
    }
}
export default pushWarning